<script lang="ts">
import util from '@/utils/util'
import map from '@/utils/map'
import {mapState} from 'pinia'
import {mainStore, userStore} from '@/store'

export default {
	computed: {
		...mapState(mainStore, ['location', 'local', 'showShift','cacheVer']),
		...mapState(userStore, ['auth'])
	},
  onLaunch () {
		uni.$store.main.showAuth && (uni.$store.main.showAuth = false)
		// 自动登录
		// #ifdef MP-WEIXIN
		!this.auth && uni.login({
			success (res) {
				uni.$u.http.get('wemini/auth',{code:res.code}).then(resp=>{
					uni.$store.user.login(resp)
				}).catch(e=>{
					uni.$store.user.clear()
				})
			}
		})
		// #endif
		// #ifdef APP-PLUS-NVUE
		// 锁定屏幕方向
		plus.screen.lockOrientation('portrait-primary');
		// 检测升级
		uni.$u.http.get('upgrade', {
			appid: plus.runtime.appid,
			version: plus.runtime.version,
			imei: plus.device.imei
		}).then(res => {
			if (res.result.isUpdate) {
				const openUrl = plus.os.name === 'iOS' ? res.result.iOS : res.result.Android
				util.prompt('是否选择更新', () => plus.runtime.openURL(openUrl))
			}
		}).catch(()=>{})
		// #endif
		// 定位
		const that = this
		map.location(res=>{
			if(that.location.address == ''){
				uni.$u.http.put('city/change', {id: res.city_id}).then(()=>{
					uni.$store.main.update({location: res, local: res})
				}).catch(e=>{})
			} else {
				uni.$store.main.update({
					local: res,
					showShift: that.location.city_id!=res.city_id
				})
				if(res.city_id!=that.location.city_id){
					setTimeout(()=>{
						uni.$store.main.update({showShift: false})
					}, 10000)
				}
			}
		}, () => {
			if(that.location.address==''){
				uni.$store.main.update({showShift: true})
				// util.msg('无法定位,请开启定位')
			}
		})
	},
  onShow () {
    // console.log('App Show')
  },
  onHide () {
    // console.log('App Hide')
  }
}
</script>

<style lang="scss">
/* #ifndef APP-PLUS */
@font-face {
	font-family: 'icon';  /* Project id 1493359 */
	src: 
		url('https://at.alicdn.com/t/font_1493359_i715gzx1ir.woff2?t=1638334998969') format('woff2'),
    url('https://at.alicdn.com/t/font_1493359_i715gzx1ir.ttf?t=1638334998969') format('truetype'),
    url('https://at.alicdn.com/t/font_1493359_i715gzx1ir.svg?t=1638334998969#icon') format('svg');
}
/* #endif */
/* #ifdef APP-PLUS */
@font-face {
	font-family: 'icon';  /* Project id 1493359 */
	src: url('./static/font.woff2?t=1624111431694') format('woff2');
}
/* #endif */
.icon{
	font-family:"icon" !important;
	font-size:16px;
	font-style:normal;
	-webkit-font-smoothing: antialiased;
	-webkit-text-stroke-width: 0.05px;
	-moz-osx-font-smoothing: grayscale;
	text-align: center;
}
@import "./app.scss";
@import "uview-plus/index.scss";
</style>